import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"

export const columns: BasicColumn[] = [
  {
    title: "traceId",
    dataIndex: "traceId",
    width: 140,
    align: "left",
  },
  {
    title: "操作人员",
    dataIndex: "userName",
    width: 100,
    customRender: ({ text }) => {
      return text ? text : "-"
    },
  },
  {
    title: "操作地址",
    dataIndex: "userIp",
    width: 130,
  },
  {
    title: "业务类型",
    dataIndex: "typeName",
    width: 120,
    customRender: ({ text }) => {
      return text ? text : "-"
    },
  },
  {
    title: "业务子类型",
    dataIndex: "subTypeName",
    width: 140,
    customRender: ({ text }) => {
      return text ? text : "-"
    },
  },
  {
    title: "操作内容",
    dataIndex: "action",
    width: 150,
    customRender: ({ text }) => {
      return text ? text : "-"
    },
  },
  {
    title: "状态",
    dataIndex: "status",
    width: 60,
    customRender: ({ text }) => {
      const color = text ? "green" : "red"
      return render.renderTag(text ? '成功' : '失败', color)
    },
  },
  {
    title: "操作日期",
    dataIndex: "createdAt",
    width: 150,
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: "userName",
    label: "操作人员",
    component: "Input",
    colProps: { span: 8 },
  },
  {
    field: "logTypeId",
    label: "业务", 
    component: "MyTreeSelect",
    colProps: { span: 8 },
  },
  {
    field: "traceId",
    label: "traceId",
    component: "Input",
    colProps: { span: 8 },
  },
  {
    label: '状态',
    field: 'status',
    component: "Select",
    defaultValue: null,
    componentProps: {
      placeholder: "全部",
      options: [
        { label: "全部", value: null },
        { label: "启用", value: true },
        { label: "停用", value: false },
      ],
    },
    colProps: { span: 8 },
  },
  {
    field: "createdAt",
    component: "RangePicker",
    label: "操作时间",
    colProps: {
      span: 8,
    },
  },
]

export const formDescSchema = [
  {
    field: "traceId",
    label: "请求ID",
  },
  {
    field: "costTime",
    label: "耗时",
    render: (curVal, data) => {
      const color = curVal >= 500 ? "red" : "green"
      return render.renderTag(curVal + " ms", color)
    },
  },
  {
    field: "typeName",
    label: "业务类型",
  },
  {
    field: "subTypeName",
    label: "子类型",
  },
  {
    field: "bizId",
    label: "业务编号",
  },
  {
    field: "userIp",
    label: "操作者IP",
  },
  {
    field: "location",
    label: "操作地点",
  },
  {
    field: "userName",
    label: "操作人员",
  },
  {
    field: "action",
    label: "操作内容",
  },
  {
    field: "requestMethod",
    label: "请求方式",
  },
  {
    field: "requestUrl",
    label: "请求url",
  },
  {
    field: "status",
    label: "操作状态",
    render: (curVal, data) => {
      const color = curVal ? "green" : "red"
      return render.renderTag(curVal ? '成功' : '失败', color)
    },
  },
  {
    field: "createdAt",
    label: "操作日期",
  },
]
